import { Component, Input, Output, EventEmitter } from '@angular/core';
/*import { BrowserModule } from '@angular/platform-browser';
import { DialogsModule } from '@progress/kendo-angular-dialog';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { ButtonsModule } from '@progress/kendo-angular-buttons';*/

/**
 * 类名: DialogData&sp
 * properties: [
 * data: 事件传回数据
 * result: 点击（按钮）事件类型
 * component: 发出事件的组件
 * random: 随机数
 * ]
 */
class DialogData {
    data: any;
    result: any;
    component: any;
    random: number;
}

@Component({
    selector: 'my-kendo-dialog',
    styleUrls: ['./my.kendo.dialog.component.css'],
    templateUrl: './my.kendo.dialog.component.html'
})
export class MyKendoDialogComponent {
    @Input() public dialogOpened = false;
    @Input() public windowOpened = false;
    @Input() public button2;
    @Input() public button1 = '知道了';
    @Input() public title = '请确认';
    @Input() public description;
    @Output() public clickEventEmitter = new EventEmitter();
    /**点击x关闭对话框 */
    public close(component) {
        this[component + 'Opened'] = false;
        let data = new DialogData;
        data.component = component;
        this.clickEventEmitter.emit(data);
    }
    /**打开对话框 */
    public open(component) {
        this[component + 'Opened'] = true;
    }
    /**点击按钮调用方法 */
    public action(status, component) {
        //console.log(`Dialog result: ${status}`);
        this[component + 'Opened'] = false;
        let data = new DialogData;
        data.result = status;
        data.component = component;
        data.random = this.RndNum(4);
        this.clickEventEmitter.emit(data);
    }
    /**产生n位随机数的函数 */
    public RndNum(n): number {
        var rnd = "";
        for (var i = 0; i < n; i++) {
            if (i == 0) {
                let x = 0;
                while (x == 0) {
                    x = Math.floor(Math.random() * 10);
                }
                rnd += x;
            } else
                rnd += Math.floor(Math.random() * 10);
        }
        return +rnd;
    }
}
